package com.mbl.phone.service;

import com.mbl.phone.dao.DataDao;
import com.mbl.phone.pojo.Changjia;
import com.mbl.phone.pojo.User;
import java.sql.Timestamp;
import java.util.List;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;


@Service
public class DataServiceImpl
implements DataService
{
	static final Logger logger = LoggerFactory.getLogger(DataService.class);

	@Resource
	DataDao dataDao;

	public List<Changjia> findTenData(Integer genre)
	{
		return this.dataDao.findTenData(genre);
	}

	public Integer updateChangJia(Changjia changjia)
	{
		return this.dataDao.updateChangJia(changjia);
	}

	public Long findStatusByChangjia(Long id)
	{
		return Long.valueOf(this.dataDao.findStatusByChangjia(id));
	}

	public List<Long> findBackListByNum(Integer num)
	{
		return this.dataDao.findBackListByNum(num);
	}

	public Integer updataBlackList(Integer num)
	{
		return Integer.valueOf(this.dataDao.updataBlackList(num));
	}

	public Integer updataChangJiaAddBackList(Long id, Long userId)
	{
		logger.info("用户" + userId + "  拉黑客户(id=" + id + ")");
		return this.dataDao.updataChangJiaAddBackList(id, userId);
	}

	public Integer updataChangJiaMarkHigh(Long id, Long userId)
	{
		Changjia data = this.dataDao.findChangJiaById(id);

		if ((data.getContribution_id() == userId.longValue()) || (data.getStatus() == 0)) {
			Integer updataChangJiaMarkHigh = this.dataDao.updataChangJiaMarkHigh(id, userId);
			logger.info("用户" + userId + " 添加优质客户(id=" + id + "),添加结果为:" + updataChangJiaMarkHigh);
			return updataChangJiaMarkHigh;
		}
		return Integer.valueOf(0);
	}

	public Integer updataChangjia(Long id, Changjia changjia, Long userId)
	{
		Changjia data = this.dataDao.findChangJiaById(id);
		if ((data.getContribution_id() == userId.longValue()) || (data.getStatus() == 0)) {
			changjia.setUpdata_time(new Timestamp(System.currentTimeMillis()));
			changjia.setStatus(7);
			changjia.setSign(8);
			changjia.setContribution_id(userId.longValue());
			Integer ifModify = this.dataDao.updateChangJia(changjia);
			logger.info("用户" + userId + " 添加有效客户(id=" + id + "),添加结果为:" + ifModify);
			return ifModify;
		}
		return Integer.valueOf(0);
	}


	public List<Changjia> findChangJiaSignTen(int sign, int endItem, User user)
	{
		logger.info("用户" + user.getNickname() + " 查看sign(" + sign + ")第" + endItem + "条(+10)");
		return this.dataDao.findChangJiaSignTen(sign, endItem, user.getId());
	}

	public Changjia findChangjiaById(Long dataId)
	{
		return this.dataDao.findChangJiaById(dataId);
	}

	public Integer deleteChangjiaAlways(int dataId, User user)
	{
		return this.dataDao.deleteChangjiaAlways(dataId, user.getId());
	}
}


